package huixue.cn.com.rxapp.rx;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v7.widget.AppCompatButton;
import android.view.View;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import huixue.cn.com.rxapp.R;
import huixue.cn.com.rxapp.base.SimpleActivity;
import huixue.cn.com.rxapp.login.service.MyService;

public class StartServiceActivity extends SimpleActivity {

    @BindView(R.id.btn_start_service)
    AppCompatButton btnStartService;
    @BindView(R.id.btn_stop_service)
    AppCompatButton btnStopService;
    @BindView(R.id.btn_bind_service)
    AppCompatButton btnBindService;
    @BindView(R.id.btn_unbind_service)
    AppCompatButton btnUnbindService;

    @Override
    public int getLayout() {
        return R.layout.activity_start_service;
    }

    @Override
    public void initView() {

    }

    @Override
    public void addEvent() {

    }

    private Intent intent = null;
    @OnClick({R.id.btn_start_service, R.id.btn_stop_service,
              R.id.btn_bind_service, R.id.btn_unbind_service})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_start_service:
                intent = new Intent(this, MyService.class);
                startService(intent);
                break;
            case R.id.btn_stop_service:
                stopService(intent);
                break;
            case R.id.btn_bind_service:
                bindService(intent,serviceConnection, MyService.BIND_AUTO_CREATE);
                break;
            case R.id.btn_unbind_service:
                unbindService(serviceConnection);
                break;
        }
    }

    ServiceConnection serviceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {

        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };

}
